<?php
include ('../../configs/cms.php');
include ('../includes/index.php');
include ('../includes/404.php');
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
	if ($_SESSION['which'] == 'choose1')
	{
		$_SESSION['which'] = 'choose2';
		$query1 = mysql_query("SELECT titel, inhoud, kant FROM kolom WHERE `kolom_id` = '" . $_POST['kolom_id'] . "'");
		$result1 = mysql_fetch_assoc($query1);
		?>
		<script type="text/javascript" src="includes/ckeditor/ckeditor.js"></script>
		<div style="margin-left: 40px;"><form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
		Titel:<br>
		<input type="text" name="titel" size="20" maxlength="30" value="<?php echo $result1['titel']; ?>">
		<br /><br />
		Inhoud:<br>
		<textarea class="ckeditor" name="inhoud" id="inhoud" rows="30" cols="100" wrap="soft" maxlength="500"><?php echo $result1['inhoud']; ?></textarea>
		<script type="text/javascript">
		CKEDITOR.replace( 'inhoud' ); 

		</script>
		<br><br>
		Kant:<br>
		<input type="text" name="kant" size="1" maxlength="1" value="<?php echo $result1['kant']; ?>">
		<input type="hidden" name="kolom_id" value="<?php echo $_POST['kolom_id']; ?>">
		<br /><br />
		<input type="submit" value="Sla gewijzigde kolom op">&nbsp;&nbsp;<input type="reset" value="Leeg formulier">
		</form></div><?php
	}
	elseif ($_SESSION['which'] == 'choose2')
	{
		$titel = $_POST['titel'];
		$inhoud = $_POST['inhoud'];
		$kolom_id = $_POST['kolom_id'];
		$kant = $_POST['kant'];
		
		if (strlen($titel) > 255 || empty($titel))
		{
			echo 'De titel is te lang of niet ingevuld<br>
			<a href="#back" onclick="history.go(-1)">Ga terug</a> om het te wijzigen.';
		}
		elseif (strlen($kant) > 1)
		{
			echo 'De kant is te lang of niet ingevuld<br>
			<a href="#back" onclick="history.go(-1)">Ga terug</a> om het te wijzigen.';
		}
		elseif (strlen(trim(strip_tags($inhoud))) > 500 || !trim(strip_tags($inhoud)))
		{
			echo 'Je hebt te veel tekst geplaatst (max 500 tekens) of niets ingevuld<br>
			<a href="#back" onclick="history.go(-1)">Ga terug</a> om het te wijzigen.';
		}
		else
		{
			$sql = "UPDATE `kolom` SET `titel` = '" . $titel . "', `inhoud` = '" . $inhoud . "', `kant` = '" . $kant . "' WHERE `kolom_id` = '" . $kolom_id . "';";
			mysql_query($sql);
			echo 'De kolom ' . $titel . ' is met succes gewijzigd.';
		}
	}
}
else
{
?>
	<div style="margin-left: 40px;"><form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
	Welke kolom:<br />
	<?php
	$_SESSION['which'] = 'choose1';
	$query = mysql_query ("SELECT kolom_id, titel FROM kolom WHERE active = 1;");
	echo '<select name="kolom_id">';
	while ($result = mysql_fetch_assoc ($query))
	{
		echo '<option value="' . $result['kolom_id'] . '">' . $result['titel'] . '</option>' . "\n";
	}
	echo '</select>';
	?>
	<br /><br />
	<input type="submit" value="Wijzig kolom">&nbsp;&nbsp;<input type="reset" value="Leeg formulier"></form></div>
<?php
}
//print_r ($_SESSION);
?>
